package com.syerit.view
{
	import com.syerit.ApplicationFacade;
	import com.syerit.model.ConfigProxy;
	
	import flash.events.Event;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class MainPageMediator extends Mediator implements IMediator
	{
		// Cannonical name of the Mediator
        public static const NAME:String = "MainPageMediator";
        
        private var configProxy:ConfigProxy;
        
		public function MainPageMediator(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
			configProxy = facade.retrieveProxy(ConfigProxy.NAME) as ConfigProxy;
			page.addEventListener(MainPage.CREATION_COMPLETE,initApp);
		}
		private function initApp(e:Event):void
		{
			configProxy.load();
		}
		/**
         * List all notifications this Mediator is interested in.
         * <P>
         * Automatically called by the framework when the mediator
         * is registered with the view.</P>
         * 
         * @return Array the list of Nofitication names
         */

		override public function listNotificationInterests():Array
		{
			return [
			ApplicationFacade.LOADING_COMPLETE
			];
		}
		
		/**
         * Handle all notifications this Mediator is interested in.
         * <P>
         * Called by the framework when a notification is sent that
         * this mediator expressed an interest in when registered
         * (see <code>listNotificationInterests</code>.</P>
         * 
         * @param INotification a notification 
         */

		override public function handleNotification(notification:INotification):void
		{
			switch ( notification.getName() ) 
            {
                case ApplicationFacade.VIEW_SPLASH_SCREEN:
                    //app.vwStack.selectedIndex = SPLASH_SCREEN;
                    break;

                case ApplicationFacade.VIEW_MAIN_SCREEN:
                    //app.vwStack.selectedIndex = MAIN_SCREEN;
                    break;
            }

		}
		protected function get page():MainPage
		{
			return viewComponent as MainPage
		}
	}
}